﻿@model BrnMall.Web.StoreAdmin.Models.OrderInfoModel

@section header{
    <title>订单信息</title>
    <link type="text/css" rel="stylesheet" href="/admin_store/css/site.css"/>
    <link type="text/css" rel="stylesheet" href="/components/jbox/Skins/Default/jbox.css" />
    <script type="text/javascript" src="/admin_store/scripts/jquery.js"></script>
    <script type="text/javascript" src="/components/jbox/jquery.jBox-2.3.min.js"></script>
    <style type="text/css">
    body{ background-color:#f0f2f5;}
    .addTable{padding-top:0px;background-color:#f0f2f5;}
    table {background-color: #fff;}
    .addTable table{width:100%; margin-bottom:10px; } 
    .addTable table th{ background:#dbeffa; font-weight:normal;height:28px; line-height:26px; padding-left:10px;} 
    .addTable table th a{ padding-left:8px;} 
    .addTable table td{ height:26px; line-height:26px; padding-left:10px; background-color:inherit; }
    .addTable table td.pImg{ padding:10px; }
    .td-line { border-left:solid 1px #dbeffa}
    body .sleep { background-color:#ccc;}
    </style>
}

@section body{
<h1 class="rightH1">
	微信小程序 &gt; 订单管理 &gt; <span class="rightH1-cur">订单信息</span>
<div class="right">
<a href="@Html.Raw(ViewData["referer"].ToString())" class="menuBT"><img src="/admin_store/images/goback.jpg"/>返回列表</a>
<div class="clear"></div>
</div>
<div class="clear"></div>
</h1>

@using (Html.BeginForm())
{
    <div class="addTable">
        <table>
            <tr><th colspan="4" align="left">管理操作</th></tr>
            <tr>
                <td style="width:100px;height:45px">
                    @{
                        OrderState orderState = (OrderState)Model.OrderInfo.OrderState;
                        if (((int)orderState <= 100) && Model.OrderInfo.ShipCoName.Contains("达达"))
                        {
                    <a href="@Url.Action("cancelorderbyship", new { oid = Model.OrderInfo.Oid, osn = Model.OrderInfo.OSN, address = Model.OrderInfo.Address, ShipName = Model.OrderInfo.ShipCoName })"
                       class="a-button">取消配送</a>
                        }
                        if (orderState == OrderState.WaitPaying)
                        {
                    <a href="@Url.Action("cancelorder", new { oid = Model.OrderInfo.Oid })" class="a-button">取消</a>
                    <a href="@Url.Action("lockorder", new { oid = Model.OrderInfo.Oid })" class="a-button">锁定</a>
                    <a href="@Url.Action("updateorderdiscount", new { oid = Model.OrderInfo.Oid })" class="a-button">修改折扣</a>
                    <a href="@Url.Action("updateordershipfee", new { oid = Model.OrderInfo.Oid })" class="a-button">修改配送费用</a>
                        }
                        else if (orderState == OrderState.Confirming)
                        {
                            if (Model.OrderInfo.PayMode == 0)
                            {
                    <a href="@Url.Action("cancelorder", new { oid = Model.OrderInfo.Oid })" class="a-button">取消</a>
                    <a href="@Url.Action("lockorder", new { oid = Model.OrderInfo.Oid })" class="a-button">锁定</a>
                    <a href="@Url.Action("updateorderdiscount", new { oid = Model.OrderInfo.Oid })" class="a-button">输入减免金额</a>
                    <a href="@Url.Action("updateordershipfee", new { oid = Model.OrderInfo.Oid })" class="a-button">修改配送费用</a>
                            }
                    <a href="@Url.Action("confirmorder", new { oid = Model.OrderInfo.Oid })" class="a-button">确认</a>
                        }
                        else if (orderState == OrderState.Confirmed)
                        {
                    <a href="@Url.Action("preorderproduct", new { oid = Model.OrderInfo.Oid })" class="a-button">备货</a>
                        }
                        else if (orderState == OrderState.PreProducting)
                        {
                    <a href="@Url.Action("sendorderproduct", new { oid = Model.OrderInfo.Oid })" class="a-button">发货</a>
                        }
                    }
                </td>
            </tr>
        </table>
        <table class="table-gb">
            <tr><th colspan="4" align="left">基本信息</th></tr>
            <tr>
                <td width="150px">订单序号：</td>
                <td width="320px">@Model.OrderInfo.Oid</td>
                <td width="150px" class="td-line">订单编号：</td>
                <td>@Model.OrderInfo.OSN</td>
            </tr>
            <tr>
                <td width="150px">订单状态：</td>
                <td>
                    @switch ((OrderState)Model.OrderInfo.OrderState)
                    {
                        case OrderState.WaitPaying:
                    @:等待付款
                        break;
                        case OrderState.Confirming:
                    @:待确认
                        break;
                        case OrderState.Confirmed:
                    @:已确认
                        break;
                        case OrderState.PreProducting:
                    @:备货中
                        break;
                        case OrderState.Sended:
                    @:已发货
                        break;
                        case OrderState.Received:
                    @:已收货
                        break;
                        case OrderState.Cancelled:
                    @:取消
                        break;
                        case OrderState.Locked:
                    @:锁定
                        break;
                        default:
                    @:未知状态
                        break;
                    }
                </td>
                <td class="td-line">下单时间：</td>
                <td>@Model.OrderInfo.AddTime</td>
            </tr>
            <tr>
                <td width="150px">配送分类：</td>
                <td width="320px">
                    @if (Model.OrderInfo.RegionId < 1)
                    {
                        if (Model.OrderInfo.Sid.Trim() != "")
                        {
                            @:堂食
                        }
                        else
                        {
                            @:自提
                        }
                    }
                    else
                    {
                        @:线上配送
                    }
                </td>
                <td width="150px">预约时间：</td>
                <td>
                    @if (Model.OrderInfo.BookStartTime.Year != 1900)
                    {
                        @Model.OrderInfo.BookStartTime.ToString("yyyy-MM-dd HH:mm:ss")
                        @:- @Model.OrderInfo.BookEndTime.ToString("yyyy-MM-dd HH:mm:ss"))
                    }
                </td>
            </tr>

            @if (Model.OrderInfo.Sid.Trim() != "")
            {
            <tr>
                <td width="150px">餐桌号：</td>
                <td width="320px">@Model.OrderInfo.Sid</td>
                <td width="150px"></td>
                <td></td>
            </tr>
            }

        </table>

        <table class="table-gb">
            <tr><th colspan="4" align="left">用户信息</th></tr>
            <tr>
                <td width="150px">用户编号：</td>
                <td width="320px">@Model.UserInfo.Uid</td>
                <td width="150px" class="td-line">用户名：</td>
                <td>@Model.UserInfo.UserName</td>
            </tr>
            <tr>
                <td>真实姓名：</td>
                <td>@Model.UserInfo.RealName</td>
                <td class="td-line">性别：</td>
                <td>
                    @{
                        switch (Model.UserInfo.Gender)
                        {
                            case 0: @:未知 
                            break;
                            case 1: @:男 
                            break;
                            case 2: @:女 
                            break;
                            default:@:未知 
                            break;
                        }
                    }
                </td>
            </tr>
            <tr>
                <td>用户昵称：</td>
                <td>@Model.UserInfo.NickName</td>
                <td class="td-line">用户等级：</td>
                <td>@Model.UserRankInfo.Title</td>
            </tr>
            <tr>
                <td>邮箱号：</td>
                <td>@Model.UserInfo.Email</td>
                <td class="td-line">手机号：</td>
                <td>@Model.UserInfo.Mobile</td>
            </tr>
        </table>

        <table class="table-gb">
            <tr><th colspan="4" align="left">配送信息</th></tr>
            <tr>
                <td width="150px">配送方式：</td>
                <td width="320px">@Model.OrderInfo.ShipCoName</td>
                <td width="150px" class="td-line">配送时间：</td>
                <td>
                    @if (Model.OrderInfo.OrderState <= (int)OrderState.PreProducting)
                    {
                        @:未配送
                    }
                    else
                    {
                        @Model.OrderInfo.ShipTime
                    }
                </td>
            </tr>
            <tr>
                <td>物流订单：</td>
                <td>@Model.OrderInfo.ShipSN</td>
                <td class="td-line">配送费用：</td>
                <td>@Model.OrderInfo.ShipFee</td>
            </tr>
        </table>
        
        @if (Model.OrderInfo.OrderState == (int)OrderState.Sended)
        {
            <table class="table-gb">
                <tr><th colspan="2" align="left">物流信息</th></tr>
                <tr><td colspan="2" style="height:45px;"><a><input type="button" class="button refrush-gistics" value="刷新物流进度" onclick="refrushGistics()" /></a></td></tr>
                <tbody class="gistics-list">

                </tbody>
            </table>
        }        

        <table class="table-gb">
            <tr><th colspan="4" align="left">支付信息</th></tr>
            <tr>
                <td width="150px">支付方式：</td>
                <td width="320px">@Model.OrderInfo.PayFriendName</td>
                <td width="150px" class="td-line">支付时间：</td>
                <td>
                    @if (Model.OrderInfo.OrderState <= (int)OrderState.WaitPaying)
                    {
                        @:未支付
                    }
                    else
                    {
                        @Model.OrderInfo.PayTime
                    }
                </td>
            </tr>
            <tr>
                <td>支付单号：</td>
                <td>@Model.OrderInfo.PaySN</td>
                <td class="td-line"></td>
                <td></td>
            </tr>
        </table>

        <table class="table-gb">
            <tr><th colspan="4" align="left">收货地址</th></tr>
            <tr>
                <td width="150px">收货人：</td>
                <td width="320px">@Model.OrderInfo.Consignee</td>
                <td width="150px" class="td-line">邮箱：</td>
                <td>@Model.OrderInfo.Email</td>
            </tr>
            <tr>
                <td>手机号：</td>
                <td>@Model.OrderInfo.Mobile</td>
                <td class="td-line">固话号：</td>
                <td>@Model.OrderInfo.Phone</td>
            </tr>
            <tr>
                <td>邮编：</td>
                <td>@Model.OrderInfo.ZipCode</td>
                <td class="td-line">最佳时间：</td>
                <td>
                    @if (Model.OrderInfo.BestTime.Year > 2000)
                    {
                        @Model.OrderInfo.BestTime
                    }
                </td>
            </tr>
            <tr>
                <td>配送地址：</td>
                <td colspan="3">
                    @if (Model.RegionInfo != null)
                    {
                        @Model.RegionInfo.ProvinceName @Model.RegionInfo.CityName @Model.RegionInfo.Name @Model.OrderInfo.Address
                    }
                </td>
            </tr>
        </table>

        <table>
            <tr>
                <th width="50%">订单商品</th>
                <th width="140">货号</th>
                <th width="80">价格</th>
                <th width="50">数量</th>
                <th width="80">小计</th>
            </tr>
            @foreach (OrderProductInfo info in Model.OrderProductList)
            {
                <tr>
                    <td style="position:relative;">
                        <img width="60px" height="60px" src="@WorkContext.ImageCDN/upload/store/@{@info.StoreId}/product/show/source/@info.ShowImg" />
                        <div style="position:absolute; left:75px; top:7px">
                            @info.Name
                            <br />
                            @if (info.BookStartTime.Year != 1900)
                            {
                                @info.BookStartTime.ToString("yyyy-MM-dd")
                                @:-
                                @info.BookEndTime.ToString("yyyy-MM-dd")
                            }
                        </div>
                    </td>
                    <td>@info.PSN</td>
                    <td>@info.DiscountPrice</td>
                    <td>@info.RealCount</td>
                    <td>@Html.Raw((info.DiscountPrice * info.BuyCount).ToString())</td>
                </tr>
            }
        </table>

        <table class="table-gb">
            <tr><th colspan="4" align="left">订单金额</th></tr>
            <tr>
                <td width="150px">订单合计：</td>
                <td width="320px">@Model.OrderInfo.OrderAmount</td>
                <td width="150px" class="td-line">实付金额：</td>
                <td>@Model.OrderInfo.SurplusMoney</td>
            </tr>
            <tr>
                <td>商品总额：</td>
                <td>@Model.OrderInfo.ProductAmount</td>
                <td class="td-line">满减：</td>
                <td>@Model.OrderInfo.FullCut</td>
            </tr>
            <tr>
                <td>积分数量：</td>
                <td>@Model.OrderInfo.PayCreditCount</td>
                <td class="td-line">积分总额：</td>
                <td>@Model.OrderInfo.PayCreditMoney</td>
            </tr>
            <tr>
                <td>优惠劵金额：</td>
                <td>@Model.OrderInfo.CouponMoney</td>
                <td class="td-line">订单折扣：</td>
                <td>@Model.OrderInfo.Discount</td>
            </tr>
            <tr>
                <td>会员等级折扣：</td>
                <td>@Model.OrderInfo.RankDiscount %</td>
                <td class="td-line">会员等级折扣金额：</td>
                <td>@Model.OrderInfo.RankDiscountMoney.ToString("0.00")</td>
            </tr>
        </table>

        <table>
            <tr><th align="left">备注信息</th></tr>
            <tr>
                <td style="padding: 0px 10px;">
                    @if (string.IsNullOrEmpty(Model.OrderInfo.BuyerRemark))
                    {
                        <span>无</span>
                    }
                    else
                    {
                        @Model.OrderInfo.BuyerRemark
                    }
                </td>
            </tr>
        </table>

        <table class="table-gb">
            <tr>
                <th width="140px">操作人</th>
                <th width="280px">操作时间</th>
                <th>操作备注：</th>
            </tr>
            @foreach (OrderActionInfo info in Model.OrderActionList)
            {
                <tr>
                    <td>@info.RealName</td>
                    <td>@info.ActionTime</td>
                    <td class="td-line">@info.ActionDes</td>
                </tr>
            }
        </table>

        <br />
    </div>
    <script>
        var isTimeSleep = false;    //等待5秒
        
        function refrushGistics() {
            if (isTimeSleep)
                return;

            loadGistics();

            isTimeSleep = true;     //开始等待
            $(".refrush-gistics").addClass("sleep");

            setTimeout(function () {
                isTimeSleep = false;    //结束等待
                $(".refrush-gistics").removeClass("sleep");
            }, 5000);
        }

        //加载物流信息
        function loadGistics() {
            $(".gistics-list").html("<tr><td collspan=2>加载中...</td></tr>");

            var api_url = "http://121.199.10.151:8011/api/order/GetOrderLogistics?isshowimg=0&oid=@Model.OrderInfo.Oid";
            $.post(api_url, "", function (data) {
                if (data.Code != 0) {
                    $.jBox.tip(data.Message);
                    return;
                }
                var html = "";
                var list = data.Data.Traces;
                if (list != null) {
                    for (var i = list.length - 1; i >= 0; i--) {
                        var item = list[i];
                        html += "<tr>";
                        html += "<td style='width:135px'>" + item.AcceptTime + "</td>";
                        html += "<td>" + item.AcceptStation + "</td>";
                        html += "</tr>";
                    }
                }

                $(".gistics-list").html(html);
            }, "json");
        }

    </script>
    }
}